package com.zhaoxi.project.fms.controller;

import com.zhaoxi.common.utils.poi.ExcelUtil;
import com.zhaoxi.framework.aspectj.lang.annotation.Log;
import com.zhaoxi.framework.aspectj.lang.enums.BusinessType;
import com.zhaoxi.framework.web.BaseService;
import com.zhaoxi.framework.web.PageData;
import com.zhaoxi.framework.web.page.TableDataInfo;
import com.zhaoxi.project.fms.domain.FmsClassificationItem;
import com.zhaoxi.project.fms.service.impl.FmsClassificationItemServiceImpl;
import jakarta.servlet.http.HttpServletResponse;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * 记账项目Controller
 *
 * @author zhaoxi
 * @date 2023-12-30
 */
@RestController
@RequestMapping("/fms/classificationItem")
public class FmsClassificationItemController extends BaseService
{
    @Autowired
    private FmsClassificationItemServiceImpl fmsClassificationItemService;

    /**
     * 分页查询记账项目列表
     */
    @PreAuthorize("@ss.hasPermi('fms:classificationItem:list')")
    @GetMapping("/list")
    public TableDataInfo list(FmsClassificationItem fmsClassificationItem)
    {
        startPage();
        List<FmsClassificationItem> list = fmsClassificationItemService.selectFmsClassificationItemList(fmsClassificationItem);
        return getDataTable(list);
    }
    

    /**
     * 导出记账项目列表
     */
    @PreAuthorize("@ss.hasPermi('fms:classificationItem:export')")
    @Log(title = "记账项目", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, FmsClassificationItem fmsClassificationItem)
    {
        List<FmsClassificationItem> list = fmsClassificationItemService.selectFmsClassificationItemList(fmsClassificationItem);
        ExcelUtil<FmsClassificationItem> util = new ExcelUtil<FmsClassificationItem>(FmsClassificationItem.class);
        util.exportExcel(response, list, "记账项目数据");
    }

    /**
     * 获取记账项目详细信息
     */
    @PreAuthorize("@ss.hasPermi('fms:classificationItem:query')")
    @GetMapping(value = "/{id}")
    public PageData getInfo(@PathVariable("id") Long id)
    {
        return success(fmsClassificationItemService.selectFmsClassificationItemById(id));
    }

    /**
     * 新增记账项目
     */
    @PreAuthorize("@ss.hasPermi('fms:classificationItem:add')")
    @Log(title = "记账项目", businessType = BusinessType.INSERT)
    @PostMapping
    public PageData add(@RequestBody FmsClassificationItem fmsClassificationItem) {
        fmsClassificationItem.setCreateBy(this.getUsername());
        return toAjax(fmsClassificationItemService.insertFmsClassificationItem(fmsClassificationItem));
    }

    /**
     * 修改记账项目
     */
    @PreAuthorize("@ss.hasPermi('fms:classificationItem:edit')")
    @Log(title = "记账项目", businessType = BusinessType.UPDATE)
    @PutMapping
    public PageData edit(@RequestBody FmsClassificationItem FmsClassificationItem)
    {
        return toAjax(fmsClassificationItemService.updateFmsClassificationItem(FmsClassificationItem));
    }
    

    /**
     * 删除记账项目
     */
    @PreAuthorize("@ss.hasPermi('fms:classificationItem:remove')")
    @Log(title = "记账项目", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public PageData remove(@PathVariable Long[] ids)
    {
        return toAjax(fmsClassificationItemService.deleteFmsClassificationItemByCodes(ids));
    }
}
